package com.keray.web.push.worker;

import com.keray.web.push.ClientMessageData;
import com.keray.web.push.WebSocket;
import com.keray.web.push.store.MessageDataStore;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

/**
 * @author by keray
 * date:2021/7/26 9:26 上午
 */
@Slf4j
public abstract class AbstractSocketWorker implements SocketWorker {

    @Resource
    protected WebSocket webSocket;

    @Resource
    protected MessageDataStore messageDataStore;

    @Override
    public ClientMessageData onSend(ClientMessageData messageData) {
        if (messageData.isSave()) messageData.setMessageId(messageDataStore.insertMessage(messageData));
        return messageData;
    }

    @Override
    public void onSendOk(ClientMessageData messageData) {
        if (messageData.isSave()) messageDataStore.sendOk(messageData.getMessageId());
    }

}
